﻿@inject IStringLocalizer<ClientNormal> Localizer

<GroupBox Title="@Localizer["GroupBoxTitle"]">
    <div class="row g-3 form-inline">
        <div class="col-12 col-sm-6">
            <Display Value="ClientInfo.Id" DisplayText="@Localizer["Id"]" ShowLabel="true" />
        </div>
        <div class="col-12">
            <Display Value="ClientInfo.RequestUrl" DisplayText="@Localizer["RequestUrl"]" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="ClientInfo.Ip" DisplayText="@Localizer["Ip"]" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="ClientInfo.OS" DisplayText="@Localizer["OS"]" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="ClientInfo.Browser" DisplayText="@Localizer["Browser"]" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="ClientInfo.Engine" DisplayText="@Localizer["Engine"]" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="ClientInfo.Device" DisplayText="@Localizer["Device"]" ShowLabel="true" />
        </div>
        <div class="col-12 col-sm-6">
            <Display Value="ClientInfo.Language" DisplayText="@Localizer["Language"]" ShowLabel="true" />
        </div>
        <div class="col-12">
            <BootstrapInput Value="ClientInfo.UserAgent" DisplayText="UserAgent" ShowLabel="true" readonly />
        </div>
    </div>
</GroupBox>

@code {
    [Inject]
    [NotNull]
    private WebClientService? ClientService { get; set; }

    private ClientInfo ClientInfo { get; set; } = new ClientInfo();

    /// <summary>
    /// OnAfterRenderAsync
    /// </summary>
    /// <param name="firstRender"></param>
    /// <returns></returns>
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);

        if (firstRender)
        {
            ClientInfo = await ClientService.GetClientInfo();
            StateHasChanged();
        }
    }
}
